$(function() {
    $('#com_bottom').load('../assets/public/html/PublicBottom.html');

    //交互：职位类型：下拉框
    $('.release_con_type_qianimg').click(function() {
        $('.release_con_type_houimg').css('display', 'initial');
        $('.release_con_type_ul').show();
        $('.release_con_type_qianimg').hide();

        if ($('.release_con_type_houimg').show()) {
            $('.release_con_type_houimg').css('display', 'initial');
            $('.release_con_type_ul').show();

            //将点击的li里的内容放入input中
            $('.release_con_type_ul > li').click(function() {
                let ReleaseType = $(this).text();
                $('#release_con_type_input').val(ReleaseType);
                $('.release_con_type_ul').hide();
                $('.release_con_type_houimg').hide();
                $('.release_con_type_qianimg').css('display', 'initial');
            })
        };
    });
    $('.release_con_type_houimg').click(function() {
        $('.release_con_type_houimg').hide();
        $('.release_con_type_ul').hide();
        $('.release_con_type_qianimg').css('display', 'initial');
    });


    //判断是否全部填写
    $('#PublishPosition_button').mouseover(() => {
        var ReleasePostInput = $('#release_con_post_input').val(); //职位
        var ReleaseTypeInput = $('#release_con_type_input').val(); //职位类型
        var ReleaseAddInput = $('#release_con_add_input').val(); //职位工作地址
        var ReleaseTimeInput = $('#release_con_time_input').val(); //每周工作时间
        var ReleaseAskInput = $('#release_con_ask_input').val(); //学历要求
        var ReleaseDescribeInput = $('#release_con_describe_input').val(); //职位描述
        var ReleasePayInputFirst = $('#release_con_pay_input_first').val();
        var ReleasePayInputEnd = $('#release_con_pay_input_end').val();
        var ReleaseYqInput = $('.ask_zwyaoqiu').val();
        var ReleaseExpInput = $('.input_experience').val();
        var ReleasePayInput = ReleasePayInputFirst + '-' + ReleasePayInputEnd + 'K'; //薪资

        if (ReleasePostInput.length != 0 && ReleaseTypeInput.length != 0 &&
            ReleaseAddInput.length != 0 && ReleaseDescribeInput.length != 0 &&
            ReleaseTimeInput.length != 0 && ReleaseAskInput.length != 0 &&
            ReleasePayInputFirst.length != 0 && ReleasePayInputEnd.length != 0) {
            $('#PublishPosition_button').css('background-color', '#FF511C');
        };

        $('#PublishPosition_button').click(() => {
            if (ReleasePostInput.length != 0 && ReleaseTypeInput.length != 0 &&
                ReleaseAddInput.length != 0 && ReleaseDescribeInput.length != 0 &&
                ReleaseTimeInput.length != 0 && ReleaseAskInput.length != 0 &&
                ReleasePayInputFirst.length != 0 && ReleasePayInputEnd.length != 0) {

                $('#PublishPosition_button').hide();
                $('#PublishPosition_sub').show();
            };
        });

        $('#PublishPosition_sub').click(() => {
            function PubPos() {
                let PublishPositionCode = Interceptor('/publicOff', 'post', {
                    'official': ReleasePostInput,
                    'offArea': ReleaseAddInput,
                    'describe': ReleaseDescribeInput,
                    'wordWeek': ReleaseTimeInput,
                    'education': ReleaseAskInput,
                    'jobMoney': ReleasePayInput,
                    'offType': ReleaseTypeInput,
                    'requirement': ReleaseYqInput,
                    'worktime': ReleaseExpInput
                });
                if (PublishPositionCode.code == 304) {
                    $('#Release_position').hide();
                    const successfully = `
                        <img src = "https://19jwshow.oss-cn-shenzhen.aliyuncs.com/recruit/icon/GreenBingo.png" alt = "">
                        <span>发布成功！</span> 
                        <a href = "PositionDetailsPage.html?id=${PublishPositionCode.data.offId}">返回已发布职位</a>
                    `
                    $('.Published_successfully').append(successfully);
                    $('#Published_successfully').show();
                } else {
                    $('#Release_position').hide();
                    const failed = `
                        <img src = "https://19jwshow.oss-cn-shenzhen.aliyuncs.com/recruit/icon/RedFalse.png" alt = "">
                        <span>发布失败！</span> 
                        <a href = "PositionDetailsPage.html?id=${PublishPositionCode.data.offId}" >返回已发布职位</a>
                    `
                    $('.Published_failed').append(failed);
                    $('#Publishing_failed').show();
                }
            }
            PubPos();
        });
    });



});